#!/bin/bash

# 获取脚本所在目录的绝对路径
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# 项目根目录（脚本所在目录的父目录）
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"

# 定义源目录和目标目录
SRC_DIR="${PROJECT_ROOT}/temp_lib"
DEST_INCLUDE_DIR="${PROJECT_ROOT}/include"
DEST_LIB_DIR="${PROJECT_ROOT}/lib"

# 创建目标目录结构
mkdir -p "${DEST_LIB_DIR}" "${DEST_INCLUDE_DIR}"

# 需要处理的库列表
LIBS=("fmt" "quill" "yaml-cpp")

for lib in "${LIBS[@]}"; do
  echo "处理库: ${lib}"

  # 复制静态库文件 (.a) 到目标 lib 目录
  find "${SRC_DIR}" -name "lib${lib}*.a" -exec cp -v {} "${DEST_LIB_DIR}" \;

  # 复制头文件到目标 include 目录
  if [ -d "${SRC_DIR}/${lib}/include/${lib}" ]; then
    mkdir -p "${DEST_INCLUDE_DIR}/${lib}"
    cp -rv "${SRC_DIR}/${lib}/include/${lib}/"* "${DEST_INCLUDE_DIR}/${lib}/"
  else
    echo "警告: ${lib} 的头文件目录 ${SRC_DIR}/${lib}/include/${lib} 不存在"
  fi
done

echo -e "\n完成整理！最终目录结构："
# tree "${PROJECT_ROOT}" -L 3